The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
0

Similarly named variables override each other

asked 2012-10-01 19:03:23 +0000

weinzierl gravatar image

updated 2012-10-01 19:31:31 +0000

If have the following in my configuration:

set $base02    #073642
set $base01    #586e75
set $base00    #ff0000
set $base0     #0000ff

#           border  background  text    indicator
client.unfocused    $base01 $base02     $base0  $base01

The result is that border, background and text are #0000ff. The value of $base00, $base01 and $base02 is overwritten by the definition of $base0. If I move the definition of $base0 in front of the other definitions it works as expected.

Whats the rationale behind this behaviour?

I'm using i3 version 4.2 (2012-04-25, branch "release-4.2").

EDIT

Removed unused reference to $yellow, because it was not relevant to the question. Sorry for the confusion.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2012-10-01 19:14:44 +0000

Michael gravatar image

updated 2012-10-04 11:17:02 +0000

You are slightly wrong: The result is the following:

ERROR: CONFIG: syntax error, unexpected $undefined
ERROR: CONFIG: in file "/tmp/570.cfg", line 153:
ERROR: CONFIG:   client.unfocused    #0000ff1 #0000ff2     #0000ff  $yellow
ERROR: CONFIG:                                                      ^

As you can see, since you have a variable called $base0, that is being replaced in $base01 and we get #0000ff1.

If you reverse the order of your variable keywords, it works as expected:

set $base0     #0000ff
set $base02    #073642
set $base01    #586e75
set $base00    #ff0000

#           border  background  text    indicator
client.unfocused    $base01 $base02     $base0  $yellow

leads to:

ERROR: CONFIG:   client.unfocused    #586e75 #073642     #0000ff  $yellow

($yellow unfixed so I can demonstrate the other replacements working properly)

This is kinda intentional — the variable mechanism is kept simple, with all the side-effects that has.

edit flag offensive delete link more

Comments

Sorry, I still don't get it. I forgot to remove the $yellow from the example, my bad, I changed the question accordingly. Why does $base0 overwrite $base01, from my understanding this are two different names. If $a is defined after, say $ab, then that changes $ab to the same value as $a.

weinzierl gravatar imageweinzierl ( 2012-10-01 19:24:31 +0000 )edit

$base0 does not overwrite anything else. It’s just the order in which the variables are replaced.

Michael gravatar imageMichael ( 2012-10-04 11:15:58 +0000 )edit

I’ve updated the formatting of the answer to make the problem more clear. Maybe that helps.

Michael gravatar imageMichael ( 2012-10-04 11:17:27 +0000 )edit

Question Tools

Stats

Asked: 2012-10-01 19:03:23 +0000

Seen: 190 times

Last updated: Oct 04 '12